<template>
  <div>
    <findMusicNav />
    <div id="one-box">
      <div class="djprogram">
        <h3 class="h3-title">推荐节目</h3>
        <div class="music-list">
          <div class="list" v-for="item in djprogram" :key="item.id">
            <div class="music">
              <div class="img">
                <img @click="albumInfo(item)" :src="item.picUrl" alt="" />
              </div>
              <div class="control">
                <div class="left">
                  <i class="iconfont font-12">&#xe600;</i>
                  &nbsp;&nbsp;<span class="font-12">{{
                    item.id | playCountFilter
                  }}</span>
                </div>
                <div class="right">
                  <i @click="albumPlay(item)" class="iconfont iconfont-cursor"
                    >&#xe638;</i
                  >
                </div>
              </div>
            </div>
            <div class="music-info" :title="item.name" @click="albumInfo(item)">
              {{ item.name }}
            </div>
          </div>
        </div>
      </div>
      <div class="programs">
        <h3 class="h3-title m-t-3">推荐电台</h3>
        <div class="music-list">
          <div class="list" v-for="item in programs" :key="item.id">
            <div class="music">
              <div class="img">
                <img @click="albumInfo(item)" :src="item.coverUrl" alt="" />
              </div>
              <div class="control">
                <div class="left">
                  <i class="iconfont font-12">&#xe600;</i>
                  &nbsp;&nbsp;<span class="font-12">{{
                    item.id | playCountFilter
                  }}</span>
                </div>
                <div class="right">
                  <i @click="albumPlay(item)" class="iconfont iconfont-cursor"
                    >&#xe638;</i
                  >
                </div>
              </div>
            </div>
            <div class="music-info" :title="item.name" @click="albumInfo(item)">
              {{ item.name }}
            </div>
          </div>
        </div>
      </div>
      <div class="privatecontent">
        <h3 class="h3-title m-t-3">独家放送</h3>
        <div class="music-list">
          <div class="list" v-for="item in privatecontent" :key="item.id">
            <div class="music h-music">
              <div
                class="img h-img"
                :style="{
                  'background-image': 'url(' + item.picUrl + ')',
                  'background-size': 'cover',
                }"
              >
                <!-- <img @click="albumInfo(item)" :src="item.picUrl" alt="" /> -->
              </div>
              <div class="control">
                <div class="left">
                  <i class="iconfont font-12">&#xe600;</i>
                  &nbsp;&nbsp;<span class="font-12">{{
                    item.id | playCountFilter
                  }}</span>
                </div>
                <div class="right">
                  <i @click="albumPlay(item)" class="iconfont iconfont-cursor"
                    >&#xe638;</i
                  >
                </div>
              </div>
            </div>
            <div class="music-info" :title="item.name" @click="albumInfo(item)">
              {{ item.name }}
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import findMusicNav from "@/components/findMusicNav";
import { mapActions } from "vuex";
import {
  personalizedDjprogram,
  programRecommend,
  personalizedPrivatecontent,
} from "@/api";
export default {
  name: "hostStation",
  components: {
    findMusicNav,
  },
  filters: {
    playCountFilter: function (val) {
      // 没有播放量 模拟 播放量 playCount
      return val.toString().slice(5);
    },
  },
  data() {
    return {
      djprogram: [],
      programs: [],
      privatecontent: [],
    };
  },
  created() {
    this.init();
  },
  methods: {
    ...mapActions("music", ["ALBUM_MUSIC_LIST_FORMAT", "SET_CHANGE_MUSIC_URL"]),
    init() {
      this.getDjprogram();
      this.getRecommendRecommend();
      this.getPrivatecontent();
    },
    getDjprogram() {
      personalizedDjprogram().then((data) => {
        this.djprogram = data.result;
      });
    },
    getRecommendRecommend() {
      programRecommend().then((data) => {
        this.programs = data.programs;
      });
    },
    getPrivatecontent() {
      personalizedPrivatecontent().then((data) => {
        this.privatecontent = data.result;
      });
    },
    albumInfo(val) {
      this.$router.push({
        name: "albumDetails",
        query: {
          id: val.id,
        },
      });
    },
    async albumPlay(val) {
      let { config, musicFlag } = await this.ALBUM_MUSIC_LIST_FORMAT(val);
      if (musicFlag) {
        config.map(async (item) => {
          await this.SET_CHANGE_MUSIC_URL(item);
        });
        this.$Notification("添加成功!", "success");
      } else {
        this.$Notification("此歌曲暂无版权。");
      }
    },
  },
};
</script>

<style lang="scss" scoped>
#one-box {
  margin-top:0;
  padding-bottom: 50px;
}
.music-list {
  display: flex;
  flex-wrap: wrap;
  // justify-content: space-between;
  .list {
    // margin: 0 6px;
    margin: 0 21px;

    margin-top: 20px;
    // margin-right:21px;
    // margin-left:21px;
    display: inline-block;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    .music {
      position: relative;
      width: 140px;
      height: 140px;
      .img {
        width: 100%;
        height: 100%;
        img {
          width: 100%;
          height: 100%;
          cursor: pointer;
        }
      }
      .control {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 12px;
        color: rgb(202, 202, 202);
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        height: 27px;
        background-image: url(../../assets/img/homepage-control.png);
        background-position: 0 -537px;
        .font-12 {
          font-size: 12px;
        }
        .iconfont {
          cursor: context-menu;
        }
        .iconfont-cursor {
          cursor: pointer;
        }
        .iconfont-cursor:hover {
          color: #fff;
        }
      }
    }
    .music-info {
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
      font-size: 14px;
      color: #000;
      width: 140px;
      &:hover {
        text-decoration: underline;
        cursor: pointer;
      }
    }
  }
}
.h3-title {
  font-size: 24px;
  color: #333;
  border-bottom: 2px solid #c20c0c;
  margin: 0 20px;
}
.m-t-3 {
  margin-top: 40px;
}
</style>